# -*- coding: utf-8 -*-

from ..extensions import db

class MovieModel(db.Model):
    # 表名
    __tablename__ = 'tb_movies'
    # 主键(id)不会自动创建，需手动创建
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    title = db.Column(db.String(60), unique=True, index=True, nullable=False)
    year = db.Column(db.String(4))

    def __init__(self, *args, **kwargs):
            super(MovieModel, self).__init__(*args, **kwargs)

    def to_json(self):
        return {
            'id': self.id,
            'title': self.title,
            'year': self.year
        }